1. Field of the Invention
This invention relates to assembly language and more particularly to apparatus and methods for detecting conflicts between assembly language statements that specify the same base register for address resolution.
2. Description of the Related Art
Unlike many programming languages, assembly language is not a single language, but typically refers to a group of languages. This is because most processor families usually have a unique instruction set and thus their own assembly language.
Unlike higher-level languages, data and program structures written in assembly language are normally implemented directly on the underlying hardware. As a result, there is often a one-to-one correspondence between symbolic instructions and executable machine codes in many assembly languages. Nevertheless, assembly languages may also include directives to the assembler, directives to the linker, directives for organizing data space, and macros, which may translate into more than one machine instruction, or alternatively, not translate into any machine instruction at all.
Notwithstanding the obvious improvement in readability, assembly languages provide a number of significant advantages over machine code. For example, assemblers often perform bookkeeping and other tasks for the programmer. One important advantage of assemblers is their use of symbolic names to represent memory locations for data and machine instructions. This frees a programmer from the laborious task of computing and re-computing memory locations whenever a program is altered.
High Level Assembler (“HLASM”) is IBM's assembler programming language and the assembler itself for the IBM z/OS, z/OS.e, OS/390, VM/ESA, z/VM, VSE/ESA, and z/VSE operating systems. Mainframes or other computers running these operating systems use an addressing scheme referred to as “base-displacement” addressing to compute the effective addresses of instruction operands of a program loaded into memory. In this scheme, effective addresses are computed by adding a “displacement” to a “base address.” The base address is generally the address where the program is loaded into memory, although other addresses may serve as the base address. The displacement is the distance between the base address and the memory location where a particular instruction operand is found. Because locations inside the program relative to the program's base address do not change once a program is converted to machine code, displacements are fixed.
When a program is loaded into memory, the mainframe loads the base address of the program into one of its general purpose registers. When this occurs, the register is used as a “base register.” At assembly time, a relative displacement is calculated for each operand, as is the base register number. The content of the base register is set at execution time, depending on the location in memory where the program is loaded.
As was previously mentioned, displacements of operands relative to the program's base address are generally fixed. However, if a programmer wishes to modify a program by inserting a statement, such as an instruction or directive, into the program source code, displacements of operands after the inserted statement are shifted relative to the program's base address in accordance to the size of the inserted statement. If the displacements are coded explicitly (i.e. using a numeric value to represent the displacement), this can be problematic since each displacement after the inserted statement needs to be recalculated relative to the program's base address.
To resolve this problem, HLASM allows a programmer to encode addresses implicitly with the USING statement. That is, addresses are represented symbolically by a label rather than by their explicit base-displacement form. When the assembler translates the program source code (written in assembly language) into object code (i.e., machine code), the assembler automatically calculates the displacement for each label and inserts these displacements into the object code. Thus, the assembler eliminates the need to recalculate new displacement values every time the program source code is modified.
In some situations, significant errors may occur if effective addresses are computed using the wrong base address. For example, such a situation may occur if two sections of program code that should operate with different base addresses use the same base register to calculate effective addresses, since a base register can only point to one base address at a time. If the base address is incorrect, the address of each operand within the program will also be incorrect.
In cases where an assembler fails to detect a conflict between two program sections that use the same base register from which to calculate effective addresses, the results can be catastrophic. Data may be read from or written to wrong locations in memory. Data may be permanently lost, overwritten, or corrupted. If this problem continues undetected, immense and potentially irreparable damage may occur.
Accordingly, what are needed are apparatus and methods for detecting conflicts in a program's source code or object code caused by two program sections using the same base register to compute effective addresses. What are also needed are apparatus and methods to notify a user or correct the conflict when detected. Further needed are specific apparatus and methods for detecting base-register conflicts for the instruction set provided for IBM's HLASM.
The present invention has been developed in response to the present state of the art, and in particular, in response to the problems and needs in the art that have not yet been fully solved by currently available apparatus, systems, and methods. Accordingly, the present invention has been developed to provide apparatus, systems, and methods for detecting base-register usage conflicts in computer code that overcome many or all of the above-discussed shortcomings in the art.